﻿using Cysharp.Threading.Tasks;
using Framework.Manager;

namespace Framework.Task
{
    public enum TaskState
    {
        Idle,
        Running,
        Finished,
    }
    
    public class Task
    {
        private string name;
        public readonly int factor = -1;
        public TaskState state;

        protected Task(int factor, string name)
        {
            this.factor = factor;
            this.name = name;
            state = TaskState.Idle;
        }

        public async UniTask Start()
        {
            state = TaskState.Running;
            
            await OnStart();
        }

        protected virtual async UniTask OnStart()
        {
            await UniTask.CompletedTask;
        }

        public void Cleanup()
        {
            
        }

        protected async UniTask OnFinished()
        {
            state = TaskState.Finished;
            await UniTask.CompletedTask;
        }

        public async UniTask Panic()
        {
            await OnPanic();
        }

        protected virtual async UniTask OnPanic()
        {
            await UniTask.CompletedTask;
        }

        protected void OnProgress(float progress)
        {
            TaskManager.Instance.OnProgress(progress);
        }
    }
}